package com.software.snowLi01.test;

import com.software.snowLi01.entity.Student;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import java.util.UUID;

/**
 * @author 23050
 * @version 1.0
 * @description: TODO
 * @date 2024/2/28 20:44
 */
public class Run {
    //保存学生信息
    public static void main(String[] args) {
        Configuration cfg = new Configuration();
        cfg.configure();

        SessionFactory sessionFactory = cfg.buildSessionFactory();
        Session session = sessionFactory.openSession();

        Transaction transaction = session.beginTransaction();

        // 处理业务逻辑
        Student student = new Student();
        student.setStudentNo("2021012411");
        student.setTelephone("15613313389");
        student.setStudentName("zhangsan");
        student.setSex("男");
        session.save(student);


        transaction.commit();
        session.close();
        sessionFactory.close();
    }



    //根据学号查找学生信息
    public static void main(String[] args) {
        Configuration cfg = new Configuration();
        cfg.configure();

        SessionFactory sessionFactory = cfg.buildSessionFactory();
        Session session = sessionFactory.openSession();

        Transaction transaction = session.beginTransaction();

        // 处理业务逻辑
        Student student = session.get(
                Student.class,
                "2021012411"
        );

        System.out.println(student);

        transaction.commit();
        session.close();
        sessionFactory.close();
    }

}
